package net.jgrm.common.util;

/**
 * 分页信息
 *
 * @author service-common
 */
public class Paging {

    /**
     * 总条数
     */
    private Long total;

    /**
     * 每页条数
     */
    private Integer pageSize;

    /**
     * 当前页码
     */
    private Integer current;

    /**
     * 默认构造函数
     */
    public Paging() {
    }

    /**
     * 构造函数
     *
     * @param total    总条数
     * @param pageSize 每页条数
     * @param current  当前页码
     */
    public Paging(Long total, Integer pageSize, Integer current) {
        this.total = total;
        this.pageSize = pageSize;
        this.current = current;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }

    /**
     * 计算总页数
     *
     * @return 总页数
     */
    public Long getTotalPages() {
        if (total == null || pageSize == null || pageSize <= 0) {
            return 0L;
        }
        return (total + pageSize - 1) / pageSize;
    }

    /**
     * 是否有下一页
     *
     * @return true:有下一页 false:没有下一页
     */
    public boolean hasNext() {
        if (current == null) {
            return false;
        }
        return current < getTotalPages();
    }

    /**
     * 是否有上一页
     *
     * @return true:有上一页 false:没有上一页
     */
    public boolean hasPrevious() {
        if (current == null) {
            return false;
        }
        return current > 1;
    }

    @Override
    public String toString() {
        return "Paging{" +
                "total=" + total +
                ", pageSize=" + pageSize +
                ", current=" + current +
                ", totalPages=" + getTotalPages() +
                '}';
    }
}